package com.yyr.spring_boot.modules.common.service.imp;

import com.yyr.spring_boot.modules.common.dao.ExceptionLogDao;
import com.yyr.spring_boot.modules.common.entity.ExceptionLog;
import com.yyr.spring_boot.modules.common.service.ExceptionService;
import com.yyr.spring_boot.modules.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class ExceptionServiceImpl implements ExceptionService {

    @Autowired
    private ExceptionLogDao exceptionLogDao;

    @Override
    public Result<ExceptionLog> insertExceptionLog(ExceptionLog exceptionLog) {
        ExceptionLog temp = exceptionLogDao.getELbyPathAndName(
                exceptionLog.getPath(), exceptionLog.getExceptionType());
        if (temp != null) {
            return new Result<ExceptionLog>(Result.ResultStatus.SUCCESS.code, "异常信息已经存在");
        }

        exceptionLog.setCreatDate(LocalDateTime.now());
        exceptionLog.setUpdateDate(LocalDateTime.now());

        exceptionLogDao.insetExceptionLog(exceptionLog);
        return new Result<ExceptionLog>(Result.ResultStatus.SUCCESS.code, "插入成功", exceptionLog);
    }
}
